Repository navigation
Conversation
…ension maxIndent on all content, including pastes maxIndent was only enforced by the INDENT_CONTENT_COMMAND handler, so a paste could bring in nested lists and indented blocks deeper than the limit. When maxIndent is set, register a transform on every element type that clamps indentation that the $canIndent predicate allows to below maxIndent, the same bound the indent command uses. Closes meta#5170 Signed-off-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Vedthakar
force-pushed
the
fix/5170-max-indent-paste
branch
from
October 21, 2026 21:37
1d51f6d to
ff08343
Compare
Owner
Author
|
Superseded by meta#9426. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This solves issue meta#5170: pasted content can go deeper than
maxIndent.Builds on meta#6718 by @mdmuhtasimfuadfahim, reworked with node transforms as @etrepum suggested there.
Current behavior.
TabIndentationExtension(andregisterTabIndentation) only enforcesmaxIndentin itsINDENT_CONTENT_COMMANDhandler (newIndent < maxIndent).data-lexical-indent/padding-inline-start.maxIndent: 7, accepts a pasted list nested 10 levels deep.What this changes. The limit is enforced with node transforms rather than commands. When
maxIndentis set,registerTabIndentationregisters a transform on every registeredElementNodeclass exceptRootNode(it walkseditor._nodes, likeNormalizeInlineElementsExtension). The transform:setIndent(maxIndent - 1)when a node'sgetIndent()is>= maxIndentand the$canIndentpredicate allows it to indent. That is the same bound the indent command uses.ListItemNode.setIndent(), which outdents through$handleOutdent, so no item or text is lost. Items deeper than the limit end up as siblings at the deepest allowed level.maxIndentisnull(or0, which the command handler also treats as no limit). For a signal, the transforms are registered and removed with aneffectas the value changes.Scope: all content, not only pastes. Because these are transforms, the cap applies to any content that ends up in the document. That includes:
setEditorState;Registering also marks every element dirty, so the whole document is checked once at registration. An existing document saved with a deeper indent is therefore clamped when it is loaded with
maxIndentset. This is documented in the JSDoc of the transform helper and ofregisterTabIndentation.Legacy plugin. Since each registration now re-checks the whole document,
TabIndentationPluginkeeps$canIndentin a ref and passes a stable predicate. The effect now depends only on[editor, maxIndent], so an inline$canIndentarrow no longer re-registers on every render. The latest predicate is still the one used (it is stored in a ref set fromuseLayoutEffect). Changing$canIndentno longer re-clamps existing content: the new predicate applies the next time a node is transformed.Closes meta#5170
Test plan
New
packages/lexical-extension/src/__tests__/unit/IndentationLimitsPaste.test.ts(maxIndent: 4):1, 9from$initialEditorStatebecome1, 3.7becomes3.0, 1, 2, 3, 3, 3, 3, with every item's text kept.2, 10, 9become2, 3, 3.New
packages/lexical-react/src/__tests__/unit/LexicalTabIndentationPlugin.test.tsx:registerNodeTransformzero times, and the new predicate is the one applied.$canIndentprop is passed.The existing
IndentationLimits.test.ts(Tab / indent command) passes unchanged.Before
On
mainwith the tests applied and the source change reverted:With the plugin from before the ref change, "does not re-register when an inline $canIndent changes" fails.
After
Author: Ved Thakar (@Vedthakar)